<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>确认付款</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
	</head>

	<body>
		<div class="mui-content qrfuk_content">
			<div class="fuk_conbox">
				<div class="fuk_ctop">
					<div class="fuk_ctimg"><img id='store_thum'></div>
					<div class="fuk_spnam"></div>
				</div>
				<div class="fuk_center">
					<div>充值金额</div>
					<div class="fuk_pribox">
						<label>¥</label>
						<input id='pay_money' onkeyup="clearNoNum(this)" type="text"></input>
					</div>
					<!--<div class="fuk_jif">
	    			<p>您本次可以使用鼓励金抵消费额度</p>
	    			<p class="fuk_jifnum"><em>80</em>鼓励金</p>
	    		</div>-->
				</div>
				<!--<p class="liuy">
					<a href="#">添加留言</a>
				</p>-->
				<button type="button" class="qrfuk_btn" id='qrfuk_btn'>确认付款</button>
			</div>
			<div class="fuk_sm" style="position: relative; margin-top: 80px;">©由龙信云商铺提供技术支持</div>
		</div>
		<!----------------悬浮框  设置支付密码 ------------------->
		<div class="mask">
			
		</div>
		<!----------------悬浮框  填写支付密码------------------->
		<div class="mask" id='pay_by_score' >
			<div class="mask_con">
				<div class="top">
					<span class="del"><button type="button" onclick="$('#pay_by_score').hide();$('#qrfuk_btn').attr('disabled', false);">X</button></span>
					<span class="tx"><img src="../images/cpimg.jpg"></span>
					<span class="wz">请输入支付密码</span>
				</div>
				<div class="xf_pribox">
					<p class="xf_fknam">向“<em id='jf_store_name'>爱上漂亮美业</em>”付款</p>
					<p class="xf_pri">¥<em id='jf_pay_money'>100</em></p>
				</div>
				<div class="xffkfs">
					<a href="#"><span class="img"><img src="../images/jinbi.gif">
				</span>该商家支持鼓励金100%抵扣付款</a>
				</div>
				<div class="xfk_btn" id='is_pay_pwd' style="display: none;"><button type="button">设置支付密码</button></div>
				<div class="pwd-box" id='pay_pwd' style="none">  
				    <input type="tel" maxlength="6" class="pwd-input" id="pwd-input">  
				    <div class="fake-box">  
				        <input type="password" readonly="">  
				        <input type="password" readonly="">  
				        <input type="password" readonly="">  
				        <input type="password" readonly="">  
				        <input type="password" readonly="">  
				        <input type="password" readonly="">  
				    </div>  
				</div> 
			</div>
			<div id="callback"></div>
			<div id="cut_back"></div>
			<input type="hidden" id='is_pwd' value=1><!--是否设置支付密码-->
		</div>
		<input type="hidden" id='order_sn'>
		<input type="hidden" id='give_score'>
	</body>

</html>
<script src="../js/mui.min.js"></script>
<script src="../js/zepto.min.js"></script>
<script type="text/javascript" src="../js/date.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script>
	$(function() {
		//记录扫码客户端，微信，或支付宝
		var pay_type = 0;
		var ua = window.navigator.userAgent.toLowerCase();
		var auth_code = getQueryString("auth_code");
		if(ua.match(/MicroMessenger/i) == 'micromessenger') {
			pay_type = 2;
		} else if(ua.match(/AlipayClient/i) == 'alipayclient') {
			pay_type = 3;
			if(auth_code == null) {
				var fromurl = location.href;
				var url = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2016030801195057&scope=auth_base&redirect_uri='+encodeURIComponent(fromurl);
				location.href = url;
			}
		}
		if(pay_type == 3){
			var res = alipay_user(auth_code,getUrlParam("fromuid"));
		}
		//获取商户信息
		$.ajax({
			url: APP.api_url + 'wallet/get_storeby_id',
			data: {
				store_id: getUrlParam("store_id")
			},
			success: function(data) {
				if(data.code == 200) {
					sessionStorage.setItem("cut_store_info", JSON.stringify(data.data)); 

					$('.fuk_spnam').text(data.data.store_name);
					$('#give_score').val(data.data.give_score);
					//图片地址
					var picture_url = user_tupian(data.data.store_logo,'../images/cpimg.jpg');
					$("#store_thum").attr('src', picture_url);
				} else {
					layer.msg('该店铺不存在');
					return false;
				}
			}
		})
		//确认付款
		$("#qrfuk_btn").click(function() {
			$("#qrfuk_btn").attr("disabled", true);
			
			var member = JSON.parse(localStorage.getItem('member'));
			
			//获取店铺信息
			var store_info = JSON.parse(sessionStorage.getItem("cut_store_info"));
			//订单编号
			$('#order_sn').val(getSn());
			
			//付款金额
			var pay_money = $("#pay_money").val();
			if(pay_money == "") {
					layer.msg('请输入充值金额');
					$("#qrfuk_btn").attr("disabled", false);
					return false;
			}
				var act = "alipay";
				var jstype = "html";
				var cut_pay_money = pay_money;
				if(pay_type == 2) {
					act = "wechat";
					jstype = "jsonp";
				}
				$.ajax({
					url: APP.api_url + 'Payment/' + act,
					data: {
						WIDout_trade_no	: $("#order_sn").val(),
						WIDsubject		: "保证金充值",
						WIDtotal_fee	: cut_pay_money,
						//WIDtotal_fee	: 0.01,
						WIDshow_url		: 'www',
						WIDbody			: "保证金充值",
						uid				: getUrlParam("store_id"),
						order_ids		: store_info['id'],
						type			: "accept",
						user_type		: 2,
						pay_money		: pay_money,
						openid			: member['openid'],
						token 			:'cheshi',
						pay_type		: pay_type
					},
					type: "post",
					dataType: jstype,
					jsonp: 'callback',
					jsonpCallback: 'jsonpCallback',
					success: function(data) {
						if(pay_type == 2) {
							callpay(data);
						} else {
							$("#callback").append(data);
						}
					}
				})
		});

	});

	//只能数字和小数点
	function clearNoNum(obj) {
		obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
		obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是.
		obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的.
		obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	}

	function jsonpCallback(data) {
		$("#cut_back").append(data);
	}
	//调用微信JS api 支付
	function jsApiCall(jsApiParameters) {
		WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParameters,
			function(res) {
				if(res.err_msg == "get_brand_wcpay_request:ok") {
					var store_info = JSON.parse(sessionStorage.getItem("cut_store_info"));
					layer.msg('付款成功！', {
						  time: 2000 
						}, function(){
							location.href="success_c.html?store_id="+store_id+"&sn="+$("#order_sn").val();
						});
				} else {
					layer.msg('付款失败');
				}
			});
	}

	function callpay(jsApiParameters) {
		console.log(jsApiParameters);
		if(typeof WeixinJSBridge == "undefined") {
			if(document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsApiParameters), false);
			} else if(document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsApiParameters));
				document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsApiParameters));
			}
		} else {
			jsApiCall(jsApiParameters);
		}
	}
</script>
